package p270jp.pxv.android.upload;

import android.app.Dialog;
import android.content.ClipData;
import android.content.ComponentCallbacks;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.os.Parcelable;
import android.provider.MediaStore;
import android.util.TypedValue;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewTreeObserver;
import android.view.inputmethod.InputMethodManager;
import android.widget.TextView;
import android.widget.Toast;
import androidx.activity.ComponentActivity;
import androidx.appcompat.app.AlertDialog;
import androidx.lifecycle.ViewModelStore;
import java.io.File;
import java.io.FileOutputStream;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Deque;
import java.util.List;
import java.util.Objects;
import p014ae.C0185y;
import p047bg.C1124a;
import p062c4.ViewBindings;
import p064c6.Preconditions;
import p081cn.progressionUtil;
import p134ei.PixivAnalytics;
import p148f7.DtsUtil;
import p189gn.AbstractC3435a;
import p216hn.DefaultConstructorMarker;
import p216hn.Lambda;
import p216hn.Reflection;
import p218hp.GrantableRequest;
import p218hp.PermissionUtils;
import p248j2.C3896b;
import p270jp.pxv.android.R;
import p270jp.pxv.android.commonObjects.model.CommentAccessType;
import p270jp.pxv.android.commonObjects.model.PixivAppApiError;
import p270jp.pxv.android.commonObjects.model.WorkType;
import p294ko.ViewModelOwner;
import p325m0.MutabilityOwnership;
import p343mi.FileProviderService;
import p350mp.Timber;
import p422ph.CameraService;
import p422ph.IllustUploadDialogService;
import p422ph.ImageDetectService;
import p436q6.StringMerger;
import p491sd.C6034a;
import p495sh.ActivityIllustUploadBinding;
import p547uh.DialogInterface$OnClickListenerC6433e5;
import p569vd.C6832d;
import p579vo.Qualifier;
import p602wl.AbstractActivityC6932c;
import p602wl.C6947t;
import p602wl.DialogInterface$OnClickListenerC6936g;
import p602wl.EditImageListener;
import p602wl.IllustUploadActivityPermissionsDispatcher;
import p602wl.UploadImagePagerAdapter;
import p603wm.AbstractC6949c;
import p625xi.LegacyNavigation;
import p628xl.C7179c;
import p628xl.C7181d;
import p628xl.IllustUploadAction;
import p628xl.IllustUploadEvent;
import p628xl.IllustUploadStore;
import p645yc.AndroidSchedulers;
import p671zc.CompositeDisposable;
import p674zf.IllustUploadParameter;

/* compiled from: IllustUploadActivity.kt */
/* renamed from: jp.pxv.android.upload.IllustUploadActivity */
/* loaded from: classes2.dex */
public final class IllustUploadActivity extends AbstractActivityC6932c {

    /* renamed from: K */
    public static final C4331a f19355K = new C4331a(null);

    /* renamed from: A */
    public ActivityIllustUploadBinding f19356A;

    /* renamed from: v */
    public boolean f19366v;

    /* renamed from: w */
    public UploadImagePagerAdapter f19367w;

    /* renamed from: x */
    public File f19368x;

    /* renamed from: y */
    public int f19369y;

    /* renamed from: z */
    public final CompositeDisposable f19370z = new CompositeDisposable();

    /* renamed from: B */
    public final AbstractC6949c f19357B = Preconditions.m9802P(1, new C4335d(this, null, null));

    /* renamed from: C */
    public final AbstractC6949c f19358C = Preconditions.m9802P(3, new C4342k(this, null, null, new C4341j(this), null));

    /* renamed from: D */
    public final AbstractC6949c f19359D = Preconditions.m9802P(3, new C4344m(this, null, null, new C4343l(this), null));

    /* renamed from: E */
    public final Deque<Dialog> f19360E = new ArrayDeque();

    /* renamed from: F */
    public final AbstractC6949c f19361F = Preconditions.m9802P(1, new C4336e(this, null, null));

    /* renamed from: G */
    public final AbstractC6949c f19362G = Preconditions.m9802P(1, new C4337f(this, null, null));

    /* renamed from: H */
    public final AbstractC6949c f19363H = Preconditions.m9802P(1, new C4338g(this, null, null));

    /* renamed from: I */
    public final AbstractC6949c f19364I = Preconditions.m9802P(1, new C4339h(this, null, null));

    /* renamed from: J */
    public final AbstractC6949c f19365J = Preconditions.m9802P(1, new C4340i(this, null, null));

    /* compiled from: IllustUploadActivity.kt */
    /* renamed from: jp.pxv.android.upload.IllustUploadActivity$a */
    /* loaded from: classes2.dex */
    public static final class C4331a {

        /* compiled from: IllustUploadActivity.kt */
        /* renamed from: jp.pxv.android.upload.IllustUploadActivity$a$a */
        /* loaded from: classes2.dex */
        public /* synthetic */ class C4332a {

            /* renamed from: a */
            public static final /* synthetic */ int[] f19371a;

            static {
                int[] iArr = new int[WorkType.values().length];
                iArr[WorkType.ILLUST.ordinal()] = 1;
                iArr[WorkType.MANGA.ordinal()] = 2;
                f19371a = iArr;
            }
        }

        public C4331a(DefaultConstructorMarker eVar) {
        }

        /* renamed from: a */
        public final Intent m4539a(Context context, WorkType workType, String str) {
            MutabilityOwnership.m3745m(context, "context");
            MutabilityOwnership.m3745m(workType, "workType");
            int i = C4332a.f19371a[workType.ordinal()];
            String str2 = i != 1 ? i != 2 ? null : "manga" : "illust";
            ArrayList arrayList = new ArrayList();
            if (str != null) {
                arrayList.add(str);
            }
            return m4538b(context, new IllustUploadParameter("", "", str2 == null ? "" : str2, "", "", null, new ArrayList(), arrayList, CommentAccessType.ALLOW), null);
        }

        /* renamed from: b */
        public final Intent m4538b(Context context, IllustUploadParameter bVar, PixivAppApiError pixivAppApiError) {
            MutabilityOwnership.m3745m(context, "context");
            MutabilityOwnership.m3745m(bVar, "parameter");
            Intent intent = new Intent(context, IllustUploadActivity.class);
            intent.putExtra("UPLOAD_PARAMETER", bVar);
            intent.putExtra("API_ERROR", pixivAppApiError);
            return intent;
        }
    }

    /* compiled from: IllustUploadActivity.kt */
    /* renamed from: jp.pxv.android.upload.IllustUploadActivity$b */
    /* loaded from: classes2.dex */
    public static final class ViewTreeObserver$OnGlobalLayoutListenerC4333b implements ViewTreeObserver.OnGlobalLayoutListener {
        public ViewTreeObserver$OnGlobalLayoutListenerC4333b() {
            IllustUploadActivity.this = r1;
        }

        @Override // android.view.ViewTreeObserver.OnGlobalLayoutListener
        public void onGlobalLayout() {
            ActivityIllustUploadBinding aVar = IllustUploadActivity.this.f19356A;
            if (aVar != null) {
                aVar.f26192C.getViewTreeObserver().removeOnGlobalLayoutListener(this);
                IllustUploadActivity illustUploadActivity = IllustUploadActivity.this;
                ActivityIllustUploadBinding aVar2 = illustUploadActivity.f19356A;
                if (aVar2 != null) {
                    aVar2.f26212q.m4591c();
                    ActivityIllustUploadBinding aVar3 = illustUploadActivity.f19356A;
                    if (aVar3 != null) {
                        aVar3.f26205j.m4591c();
                        ActivityIllustUploadBinding aVar4 = illustUploadActivity.f19356A;
                        if (aVar4 != null) {
                            aVar4.f26215t.m4591c();
                            ActivityIllustUploadBinding aVar5 = illustUploadActivity.f19356A;
                            if (aVar5 != null) {
                                aVar5.f26219x.m4591c();
                                ActivityIllustUploadBinding aVar6 = illustUploadActivity.f19356A;
                                if (aVar6 != null) {
                                    aVar6.f26209n.m4591c();
                                } else {
                                    MutabilityOwnership.m3737u("binding");
                                    throw null;
                                }
                            } else {
                                MutabilityOwnership.m3737u("binding");
                                throw null;
                            }
                        } else {
                            MutabilityOwnership.m3737u("binding");
                            throw null;
                        }
                    } else {
                        MutabilityOwnership.m3737u("binding");
                        throw null;
                    }
                } else {
                    MutabilityOwnership.m3737u("binding");
                    throw null;
                }
            } else {
                MutabilityOwnership.m3737u("binding");
                throw null;
            }
        }
    }

    /* compiled from: IllustUploadActivity.kt */
    /* renamed from: jp.pxv.android.upload.IllustUploadActivity$c */
    /* loaded from: classes2.dex */
    public static final class C4334c implements EditImageListener {
        public C4334c() {
            IllustUploadActivity.this = r1;
        }

        @Override // p602wl.EditImageListener
        /* renamed from: a */
        public void mo945a(Bitmap bitmap) {
            IllustUploadActivity illustUploadActivity = IllustUploadActivity.this;
            UploadImagePagerAdapter wVar = illustUploadActivity.f19367w;
            if (wVar != null) {
                try {
                    FileOutputStream fileOutputStream = new FileOutputStream(wVar.f29486d.get(illustUploadActivity.f19369y));
                    bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fileOutputStream);
                    fileOutputStream.close();
                } catch (Exception e) {
                    Timber.f23100a.mo3514p(e);
                }
                wVar.m7542h();
                ActivityIllustUploadBinding aVar = IllustUploadActivity.this.f19356A;
                if (aVar != null) {
                    EditImageView editImageView = aVar.f26201f;
                    editImageView.setVisibility(8);
                    editImageView.startAnimation(editImageView.f19348a);
                    ActivityIllustUploadBinding aVar2 = IllustUploadActivity.this.f19356A;
                    if (aVar2 != null) {
                        aVar2.f26190A.setVisibility(0);
                    } else {
                        MutabilityOwnership.m3737u("binding");
                        throw null;
                    }
                } else {
                    MutabilityOwnership.m3737u("binding");
                    throw null;
                }
            } else {
                MutabilityOwnership.m3737u("imageAdapter");
                throw null;
            }
        }
    }

    /* compiled from: ComponentCallbackExt.kt */
    /* renamed from: jp.pxv.android.upload.IllustUploadActivity$d */
    /* loaded from: classes2.dex */
    public static final class C4335d extends Lambda implements AbstractC3435a<CameraService> {

        /* renamed from: a */
        public final /* synthetic */ ComponentCallbacks f19374a;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        public C4335d(ComponentCallbacks componentCallbacks, Qualifier aVar, AbstractC3435a aVar2) {
            super(0);
            this.f19374a = componentCallbacks;
        }

        /* JADX WARN: Type inference failed for: r0v4, types: [ph.c, java.lang.Object] */
        @Override // p189gn.AbstractC3435a
        public final CameraService invoke() {
            return C1124a.m10173s(this.f19374a).f24118a.m920a().m621a(Reflection.m5499a(CameraService.class), null, null);
        }
    }

    /* compiled from: ComponentCallbackExt.kt */
    /* renamed from: jp.pxv.android.upload.IllustUploadActivity$e */
    /* loaded from: classes2.dex */
    public static final class C4336e extends Lambda implements AbstractC3435a<PixivAnalytics> {

        /* renamed from: a */
        public final /* synthetic */ ComponentCallbacks f19375a;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        public C4336e(ComponentCallbacks componentCallbacks, Qualifier aVar, AbstractC3435a aVar2) {
            super(0);
            this.f19375a = componentCallbacks;
        }

        /* JADX WARN: Type inference failed for: r0v4, types: [ei.e, java.lang.Object] */
        @Override // p189gn.AbstractC3435a
        public final PixivAnalytics invoke() {
            return C1124a.m10173s(this.f19375a).f24118a.m920a().m621a(Reflection.m5499a(PixivAnalytics.class), null, null);
        }
    }

    /* compiled from: ComponentCallbackExt.kt */
    /* renamed from: jp.pxv.android.upload.IllustUploadActivity$f */
    /* loaded from: classes2.dex */
    public static final class C4337f extends Lambda implements AbstractC3435a<ImageDetectService> {

        /* renamed from: a */
        public final /* synthetic */ ComponentCallbacks f19376a;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        public C4337f(ComponentCallbacks componentCallbacks, Qualifier aVar, AbstractC3435a aVar2) {
            super(0);
            this.f19376a = componentCallbacks;
        }

        /* JADX WARN: Type inference failed for: r0v4, types: [ph.g, java.lang.Object] */
        @Override // p189gn.AbstractC3435a
        public final ImageDetectService invoke() {
            return C1124a.m10173s(this.f19376a).f24118a.m920a().m621a(Reflection.m5499a(ImageDetectService.class), null, null);
        }
    }

    /* compiled from: ComponentCallbackExt.kt */
    /* renamed from: jp.pxv.android.upload.IllustUploadActivity$g */
    /* loaded from: classes2.dex */
    public static final class C4338g extends Lambda implements AbstractC3435a<IllustUploadDialogService> {

        /* renamed from: a */
        public final /* synthetic */ ComponentCallbacks f19377a;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        public C4338g(ComponentCallbacks componentCallbacks, Qualifier aVar, AbstractC3435a aVar2) {
            super(0);
            this.f19377a = componentCallbacks;
        }

        /* JADX WARN: Type inference failed for: r0v4, types: [java.lang.Object, ph.d] */
        @Override // p189gn.AbstractC3435a
        public final IllustUploadDialogService invoke() {
            return C1124a.m10173s(this.f19377a).f24118a.m920a().m621a(Reflection.m5499a(IllustUploadDialogService.class), null, null);
        }
    }

    /* compiled from: ComponentCallbackExt.kt */
    /* renamed from: jp.pxv.android.upload.IllustUploadActivity$h */
    /* loaded from: classes2.dex */
    public static final class C4339h extends Lambda implements AbstractC3435a<FileProviderService> {

        /* renamed from: a */
        public final /* synthetic */ ComponentCallbacks f19378a;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        public C4339h(ComponentCallbacks componentCallbacks, Qualifier aVar, AbstractC3435a aVar2) {
            super(0);
            this.f19378a = componentCallbacks;
        }

        /* JADX WARN: Type inference failed for: r0v4, types: [java.lang.Object, mi.a] */
        @Override // p189gn.AbstractC3435a
        public final FileProviderService invoke() {
            return C1124a.m10173s(this.f19378a).f24118a.m920a().m621a(Reflection.m5499a(FileProviderService.class), null, null);
        }
    }

    /* compiled from: ComponentCallbackExt.kt */
    /* renamed from: jp.pxv.android.upload.IllustUploadActivity$i */
    /* loaded from: classes2.dex */
    public static final class C4340i extends Lambda implements AbstractC3435a<LegacyNavigation> {

        /* renamed from: a */
        public final /* synthetic */ ComponentCallbacks f19379a;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        public C4340i(ComponentCallbacks componentCallbacks, Qualifier aVar, AbstractC3435a aVar2) {
            super(0);
            this.f19379a = componentCallbacks;
        }

        /* JADX WARN: Type inference failed for: r0v4, types: [java.lang.Object, xi.a] */
        @Override // p189gn.AbstractC3435a
        public final LegacyNavigation invoke() {
            return C1124a.m10173s(this.f19379a).f24118a.m920a().m621a(Reflection.m5499a(LegacyNavigation.class), null, null);
        }
    }

    /* compiled from: ActivityExt.kt */
    /* renamed from: jp.pxv.android.upload.IllustUploadActivity$j */
    /* loaded from: classes2.dex */
    public static final class C4341j extends Lambda implements AbstractC3435a<ViewModelOwner> {

        /* renamed from: a */
        public final /* synthetic */ ComponentActivity f19380a;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        public C4341j(ComponentActivity componentActivity) {
            super(0);
            this.f19380a = componentActivity;
        }

        @Override // p189gn.AbstractC3435a
        public ViewModelOwner invoke() {
            ComponentActivity componentActivity = this.f19380a;
            MutabilityOwnership.m3745m(componentActivity, "storeOwner");
            ViewModelStore viewModelStore = componentActivity.getViewModelStore();
            MutabilityOwnership.m3746l(viewModelStore, "storeOwner.viewModelStore");
            return new ViewModelOwner(viewModelStore, componentActivity);
        }
    }

    /* compiled from: ActivityExt.kt */
    /* renamed from: jp.pxv.android.upload.IllustUploadActivity$k */
    /* loaded from: classes2.dex */
    public static final class C4342k extends Lambda implements AbstractC3435a<C7181d> {

        /* renamed from: a */
        public final /* synthetic */ ComponentActivity f19381a;

        /* renamed from: b */
        public final /* synthetic */ AbstractC3435a f19382b;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        public C4342k(ComponentActivity componentActivity, Qualifier aVar, AbstractC3435a aVar2, AbstractC3435a aVar3, AbstractC3435a aVar4) {
            super(0);
            this.f19381a = componentActivity;
            this.f19382b = aVar3;
        }

        /* JADX WARN: Type inference failed for: r0v1, types: [androidx.lifecycle.j0, xl.d] */
        @Override // p189gn.AbstractC3435a
        public C7181d invoke() {
            return progressionUtil.m9685e(this.f19381a, null, null, this.f19382b, Reflection.m5499a(C7181d.class), null);
        }
    }

    /* compiled from: ActivityExt.kt */
    /* renamed from: jp.pxv.android.upload.IllustUploadActivity$l */
    /* loaded from: classes2.dex */
    public static final class C4343l extends Lambda implements AbstractC3435a<ViewModelOwner> {

        /* renamed from: a */
        public final /* synthetic */ ComponentActivity f19383a;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        public C4343l(ComponentActivity componentActivity) {
            super(0);
            this.f19383a = componentActivity;
        }

        @Override // p189gn.AbstractC3435a
        public ViewModelOwner invoke() {
            ComponentActivity componentActivity = this.f19383a;
            MutabilityOwnership.m3745m(componentActivity, "storeOwner");
            ViewModelStore viewModelStore = componentActivity.getViewModelStore();
            MutabilityOwnership.m3746l(viewModelStore, "storeOwner.viewModelStore");
            return new ViewModelOwner(viewModelStore, componentActivity);
        }
    }

    /* compiled from: ActivityExt.kt */
    /* renamed from: jp.pxv.android.upload.IllustUploadActivity$m */
    /* loaded from: classes2.dex */
    public static final class C4344m extends Lambda implements AbstractC3435a<IllustUploadStore> {

        /* renamed from: a */
        public final /* synthetic */ ComponentActivity f19384a;

        /* renamed from: b */
        public final /* synthetic */ AbstractC3435a f19385b;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        public C4344m(ComponentActivity componentActivity, Qualifier aVar, AbstractC3435a aVar2, AbstractC3435a aVar3, AbstractC3435a aVar4) {
            super(0);
            this.f19384a = componentActivity;
            this.f19385b = aVar3;
        }

        /* JADX WARN: Type inference failed for: r0v1, types: [androidx.lifecycle.j0, xl.f] */
        @Override // p189gn.AbstractC3435a
        public IllustUploadStore invoke() {
            return progressionUtil.m9685e(this.f19384a, null, null, this.f19385b, Reflection.m5499a(IllustUploadStore.class), null);
        }
    }

    /* renamed from: S0 */
    public static void m4553S0(IllustUploadActivity illustUploadActivity, DialogInterface dialogInterface, int i) {
        MutabilityOwnership.m3745m(illustUploadActivity, "this$0");
        UploadImagePagerAdapter wVar = illustUploadActivity.f19367w;
        if (wVar != null) {
            int m = wVar.m934m();
            if (m > 0) {
                int i2 = 0;
                while (true) {
                    int i3 = i2 + 1;
                    UploadImagePagerAdapter wVar2 = illustUploadActivity.f19367w;
                    if (wVar2 != null) {
                        ViewBindings.m9830g(wVar2.f29486d.get(i2));
                        if (i3 >= m) {
                            break;
                        }
                        i2 = i3;
                    } else {
                        MutabilityOwnership.m3737u("imageAdapter");
                        throw null;
                    }
                }
            }
            super.finish();
            return;
        }
        MutabilityOwnership.m3737u("imageAdapter");
        throw null;
    }

    /* renamed from: T0 */
    public static void m4552T0(IllustUploadActivity illustUploadActivity, IllustUploadEvent eVar) {
        MutabilityOwnership.m3745m(illustUploadActivity, "this$0");
        if (eVar instanceof IllustUploadEvent.C7182a) {
            File file = ((IllustUploadEvent.C7182a) eVar).f30136a;
            UploadImagePagerAdapter wVar = illustUploadActivity.f19367w;
            if (wVar != null) {
                MutabilityOwnership.m3745m(file, "file");
                wVar.f29486d.add(file);
                wVar.m7542h();
                UploadImagePagerAdapter wVar2 = illustUploadActivity.f19367w;
                if (wVar2 != null) {
                    int m = wVar2.m934m() - 1;
                    ActivityIllustUploadBinding aVar = illustUploadActivity.f19356A;
                    if (aVar != null) {
                        aVar.f26204i.setCurrentItem(m);
                        illustUploadActivity.m4542d1(m);
                        return;
                    }
                    MutabilityOwnership.m3737u("binding");
                    throw null;
                }
                MutabilityOwnership.m3737u("imageAdapter");
                throw null;
            }
            MutabilityOwnership.m3737u("imageAdapter");
            throw null;
        } else if (eVar instanceof IllustUploadEvent.C7184c) {
            Intent intent = ((IllustUploadEvent.C7184c) eVar).f30138a;
            MutabilityOwnership.m3745m(intent, "intent");
            String[] strArr = DtsUtil.f14190i;
            if (PermissionUtils.m5489a(illustUploadActivity, (String[]) Arrays.copyOf(strArr, strArr.length))) {
                illustUploadActivity.m4546Z0(intent);
                return;
            }
            DtsUtil.f14191j = new C6947t(illustUploadActivity, intent);
            C3896b.m5007b(illustUploadActivity, strArr, 1);
        } else if (eVar instanceof IllustUploadEvent.C7183b) {
            Toast.makeText(illustUploadActivity.getApplicationContext(), illustUploadActivity.getString(R.string.profile_registration_required_popup_upload_title), 1).show();
            super.finish();
        }
    }

    /* renamed from: U0 */
    public final PixivAnalytics m4551U0() {
        return (PixivAnalytics) this.f19361F.getValue();
    }

    /* renamed from: V0 */
    public final void m4550V0(Intent intent) {
        Objects.requireNonNull((ImageDetectService) this.f19362G.getValue());
        int i = 0;
        if (intent == null || (intent.getData() == null && intent.getClipData() == null)) {
            File file = this.f19368x;
            MutabilityOwnership.m3747j(file);
            this.f19370z.mo82c(((CameraService) this.f19357B.getValue()).m3023b(file).m961o(C6034a.f26178c).m966j(AndroidSchedulers.m334a()).m963m(new C0185y(this, 18), C6832d.f29069k));
        } else if (intent == null) {
            throw new IllegalArgumentException("Required value was null.".toString());
        } else if (intent.getClipData() != null) {
            ClipData clipData = intent.getClipData();
            MutabilityOwnership.m3747j(clipData);
            ArrayList arrayList = new ArrayList();
            int itemCount = clipData.getItemCount();
            if (itemCount > 0) {
                while (true) {
                    int i2 = i + 1;
                    Uri uri = clipData.getItemAt(i).getUri();
                    MutabilityOwnership.m3746l(uri, "clipData.getItemAt(clipDataIndex).uri");
                    arrayList.add(uri);
                    if (i2 >= itemCount) {
                        break;
                    }
                    i = i2;
                }
            }
            m4547Y0(arrayList);
        } else if (intent.getData() != null) {
            Uri data = intent.getData();
            MutabilityOwnership.m3747j(data);
            m4548X0(data, "");
        } else {
            Timber.f23100a.mo3514p(new IllegalStateException("イラスト投稿の画像選択後に想定外のデータが渡ってきています"));
        }
    }

    /* renamed from: W0 */
    public final void m4549W0(View view) {
        Object systemService = getSystemService("input_method");
        Objects.requireNonNull(systemService, "null cannot be cast to non-null type android.view.inputmethod.InputMethodManager");
        ((InputMethodManager) systemService).hideSoftInputFromWindow(view.getWindowToken(), 2);
    }

    /* renamed from: X0 */
    public final void m4548X0(Uri uri, String str) {
        C7181d dVar = (C7181d) this.f19358C.getValue();
        Objects.requireNonNull(dVar);
        MutabilityOwnership.m3745m(uri, "uploadImageUri");
        MutabilityOwnership.m3745m(str, "suffix");
        dVar.f30132c.mo2437b(IllustUploadAction.C7177d.f30113a);
        C1124a.m10167y(Preconditions.m9807K(dVar), null, 0, new C7179c(dVar, str, this, uri, null), 3, null);
    }

    /* renamed from: Y0 */
    public final void m4547Y0(List<? extends Uri> list) {
        MutabilityOwnership.m3747j(list);
        int size = list.size();
        UploadImagePagerAdapter wVar = this.f19367w;
        if (wVar != null) {
            int i = 0;
            if (wVar.m934m() + size > 20) {
                Deque<Dialog> deque = this.f19360E;
                AlertDialog.C0305a aVar = new AlertDialog.C0305a(this);
                aVar.f1085a.f1056f = getString(R.string.upload_max_count, new Object[]{20});
                aVar.m12008f(R.string.common_ok, DialogInterface$OnClickListenerC6936g.f29461b);
                deque.push(aVar.m12013a());
            }
            int size2 = list.size() - 1;
            if (size2 >= 0) {
                while (true) {
                    int i2 = i + 1;
                    m4548X0((Uri) list.get(i), String.valueOf(i));
                    if (i2 <= size2) {
                        i = i2;
                    } else {
                        return;
                    }
                }
            }
        } else {
            MutabilityOwnership.m3737u("imageAdapter");
            throw null;
        }
    }

    /* renamed from: Z0 */
    public final void m4546Z0(Intent intent) {
        MutabilityOwnership.m3745m(intent, "intent");
        String action = intent.getAction();
        if (action != null) {
            int hashCode = action.hashCode();
            if (hashCode != -1173264947) {
                if (hashCode == -58484670 && action.equals("android.intent.action.SEND_MULTIPLE")) {
                    m4547Y0(intent.getParcelableArrayListExtra("android.intent.extra.STREAM"));
                }
            } else if (action.equals("android.intent.action.SEND")) {
                Parcelable parcelableExtra = intent.getParcelableExtra("android.intent.extra.STREAM");
                MutabilityOwnership.m3747j(parcelableExtra);
                m4548X0((Uri) parcelableExtra, "");
            }
        }
    }

    /* renamed from: a1 */
    public final void m4545a1() {
        Intent intent = new Intent("android.intent.action.PICK");
        intent.setDataAndType(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, "image/*");
        intent.putExtra("android.intent.extra.ALLOW_MULTIPLE", true);
        Intent createChooser = Intent.createChooser(intent, null);
        try {
            Intent intent2 = new Intent("android.media.action.IMAGE_CAPTURE");
            File a = ((CameraService) this.f19357B.getValue()).m3024a();
            this.f19368x = a;
            intent2.putExtra("output", ((FileProviderService) this.f19364I.getValue()).m3555a(a));
            createChooser.putExtra("android.intent.extra.INITIAL_INTENTS", new Intent[]{intent2});
        } catch (IllegalStateException unused) {
        }
        startActivityForResult(createChooser, 1);
    }

    /* renamed from: b1 */
    public final void m4544b1() {
        Toast.makeText(this, (int) R.string.permission_needed_error, 1).show();
    }

    /* renamed from: c1 */
    public final void m4543c1(int i) {
        ActivityIllustUploadBinding aVar = this.f19356A;
        if (aVar != null) {
            TextView textView = aVar.f26191B;
            MutabilityOwnership.m3746l(textView, "binding.uploadCaptionCount");
            StringMerger.m2844r(textView, i, getResources().getInteger(R.integer.illust_caption_max_length));
            return;
        }
        MutabilityOwnership.m3737u("binding");
        throw null;
    }

    /* renamed from: d1 */
    public final void m4542d1(int i) {
        UploadImagePagerAdapter wVar = this.f19367w;
        if (wVar != null) {
            if (wVar.m934m() > i) {
                ActivityIllustUploadBinding aVar = this.f19356A;
                if (aVar != null) {
                    aVar.f26200e.setVisibility(0);
                    ActivityIllustUploadBinding aVar2 = this.f19356A;
                    if (aVar2 != null) {
                        TextView textView = aVar2.f26200e;
                        MutabilityOwnership.m3746l(textView, "binding.countPage");
                        int i2 = i + 1;
                        UploadImagePagerAdapter wVar2 = this.f19367w;
                        if (wVar2 != null) {
                            StringMerger.m2844r(textView, i2, wVar2.m934m());
                            UploadImagePagerAdapter wVar3 = this.f19367w;
                            if (wVar3 == null) {
                                MutabilityOwnership.m3737u("imageAdapter");
                                throw null;
                            } else if (wVar3.m934m() > 20) {
                                TypedValue typedValue = new TypedValue();
                                if (getTheme().resolveAttribute(R.attr.colorCharcoalAssertive, typedValue, true)) {
                                    int i3 = typedValue.data;
                                    ActivityIllustUploadBinding aVar3 = this.f19356A;
                                    if (aVar3 != null) {
                                        aVar3.f26200e.getBackground().setTint(i3);
                                    } else {
                                        MutabilityOwnership.m3737u("binding");
                                        throw null;
                                    }
                                } else {
                                    throw new IllegalStateException("Charcoal Theme, もしくは Charcoal Bridge Theme を利用してください");
                                }
                            } else {
                                ActivityIllustUploadBinding aVar4 = this.f19356A;
                                if (aVar4 != null) {
                                    aVar4.f26200e.getBackground().setTintList(null);
                                } else {
                                    MutabilityOwnership.m3737u("binding");
                                    throw null;
                                }
                            }
                        } else {
                            MutabilityOwnership.m3737u("imageAdapter");
                            throw null;
                        }
                    } else {
                        MutabilityOwnership.m3737u("binding");
                        throw null;
                    }
                } else {
                    MutabilityOwnership.m3737u("binding");
                    throw null;
                }
            } else {
                ActivityIllustUploadBinding aVar5 = this.f19356A;
                if (aVar5 != null) {
                    aVar5.f26200e.setVisibility(4);
                } else {
                    MutabilityOwnership.m3737u("binding");
                    throw null;
                }
            }
        } else {
            MutabilityOwnership.m3737u("imageAdapter");
            throw null;
        }
    }

    /* renamed from: e1 */
    public final void m4541e1() {
        ActivityIllustUploadBinding aVar = this.f19356A;
        if (aVar != null) {
            TextView textView = aVar.f26193D;
            MutabilityOwnership.m3746l(textView, "binding.uploadTagCount");
            ActivityIllustUploadBinding aVar2 = this.f19356A;
            if (aVar2 != null) {
                StringMerger.m2844r(textView, aVar2.f26195F.getTagCount(), 10);
            } else {
                MutabilityOwnership.m3737u("binding");
                throw null;
            }
        } else {
            MutabilityOwnership.m3737u("binding");
            throw null;
        }
    }

    /* renamed from: f1 */
    public final void m4540f1(int i) {
        ActivityIllustUploadBinding aVar = this.f19356A;
        if (aVar != null) {
            TextView textView = aVar.f26194E;
            MutabilityOwnership.m3746l(textView, "binding.uploadTitleCount");
            StringMerger.m2844r(textView, i, getResources().getInteger(R.integer.illust_title_max_length));
            return;
        }
        MutabilityOwnership.m3737u("binding");
        throw null;
    }

    @Override // android.app.Activity
    public void finish() {
        if (!this.f19366v) {
            AlertDialog.C0305a aVar = new AlertDialog.C0305a(this);
            aVar.m12012b(R.string.upload_close_confirm);
            aVar.m12008f(R.string.common_ok, new DialogInterface$OnClickListenerC6433e5(this, 2));
            aVar.m12011c(R.string.common_cancel, null);
            aVar.m12013a().show();
            return;
        }
        super.finish();
    }

    @Override // androidx.fragment.app.FragmentActivity, androidx.activity.ComponentActivity, android.app.Activity
    public void onActivityResult(int i, int i2, Intent intent) {
        super.onActivityResult(i, i2, intent);
        if (i2 == -1 && i == 1) {
            String[] strArr = DtsUtil.f14188g;
            if (PermissionUtils.m5489a(this, (String[]) Arrays.copyOf(strArr, strArr.length))) {
                m4550V0(intent);
                return;
            }
            DtsUtil.f14189h = new IllustUploadActivityPermissionsDispatcher(this, intent);
            C3896b.m5007b(this, strArr, 0);
        }
    }

    @Override // androidx.activity.ComponentActivity, android.app.Activity
    public void onBackPressed() {
        ActivityIllustUploadBinding aVar = this.f19356A;
        if (aVar == null) {
            MutabilityOwnership.m3737u("binding");
            throw null;
        } else if (aVar.f26201f.getVisibility() != 0) {
            this.f940i.m12030b();
        } else {
            ActivityIllustUploadBinding aVar2 = this.f19356A;
            if (aVar2 != null) {
                EditImageView editImageView = aVar2.f26201f;
                editImageView.setVisibility(8);
                editImageView.startAnimation(editImageView.f19348a);
                ActivityIllustUploadBinding aVar3 = this.f19356A;
                if (aVar3 != null) {
                    aVar3.f26190A.setVisibility(0);
                } else {
                    MutabilityOwnership.m3737u("binding");
                    throw null;
                }
            } else {
                MutabilityOwnership.m3737u("binding");
                throw null;
            }
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:252:0x05b8  */
    /* JADX WARN: Removed duplicated region for block: B:255:0x05d9  */
    /* JADX WARN: Removed duplicated region for block: B:266:0x0637  */
    /* JADX WARN: Removed duplicated region for block: B:269:0x0679  */
    /* JADX WARN: Removed duplicated region for block: B:279:0x06ab  */
    /* JADX WARN: Removed duplicated region for block: B:285:0x06ba  */
    @Override // androidx.fragment.app.FragmentActivity, androidx.activity.ComponentActivity, p248j2.ActivityC3902g, android.app.Activity
    /* Code decompiled incorrectly, please refer to instructions dump */
    public void onCreate(android.os.Bundle r49) {
        /*
        // Method dump skipped, instructions count: 1905
        */
        throw new UnsupportedOperationException("Method not decompiled: p270jp.pxv.android.upload.IllustUploadActivity.onCreate(android.os.Bundle):void");
    }

    @Override // p116e.ActivityC2727f, androidx.fragment.app.FragmentActivity, android.app.Activity
    public void onDestroy() {
        this.f19370z.m80f();
        super.onDestroy();
    }

    @Override // androidx.activity.ComponentActivity, android.app.Activity
    public boolean onOptionsItemSelected(MenuItem menuItem) {
        MutabilityOwnership.m3745m(menuItem, "item");
        if (menuItem.getItemId() != 16908332) {
            return true;
        }
        setResult(0);
        finish();
        return true;
    }

    @Override // androidx.fragment.app.FragmentActivity, androidx.activity.ComponentActivity, android.app.Activity
    public void onRequestPermissionsResult(int i, String[] strArr, int[] iArr) {
        MutabilityOwnership.m3745m(strArr, "permissions");
        MutabilityOwnership.m3745m(iArr, "grantResults");
        super.onRequestPermissionsResult(i, strArr, iArr);
        if (i == 0) {
            if (PermissionUtils.m5488b(Arrays.copyOf(iArr, iArr.length))) {
                GrantableRequest aVar = DtsUtil.f14189h;
                if (aVar != null) {
                    aVar.mo942a();
                }
            } else {
                m4544b1();
            }
            DtsUtil.f14189h = null;
        } else if (i == 1) {
            if (PermissionUtils.m5488b(Arrays.copyOf(iArr, iArr.length))) {
                GrantableRequest aVar2 = DtsUtil.f14191j;
                if (aVar2 != null) {
                    aVar2.mo942a();
                }
            } else {
                m4544b1();
            }
            DtsUtil.f14191j = null;
        } else if (i == 2) {
            if (PermissionUtils.m5488b(Arrays.copyOf(iArr, iArr.length))) {
                m4545a1();
            } else {
                m4544b1();
            }
        }
    }

    @Override // androidx.fragment.app.FragmentActivity, android.app.Activity
    public void onResume() {
        super.onResume();
        while (!this.f19360E.isEmpty()) {
            this.f19360E.pop().show();
        }
    }

    @Override // androidx.activity.ComponentActivity, p248j2.ActivityC3902g, android.app.Activity
    public void onSaveInstanceState(Bundle bundle) {
        MutabilityOwnership.m3745m(bundle, "outState");
        super.onSaveInstanceState(bundle);
        ActivityIllustUploadBinding aVar = this.f19356A;
        if (aVar != null) {
            bundle.putInt("edit_image_view_visibility", aVar.f26201f.getVisibility());
            ActivityIllustUploadBinding aVar2 = this.f19356A;
            if (aVar2 != null) {
                bundle.putStringArrayList("tags", aVar2.f26195F.getTagList());
                bundle.putSerializable("picture_file", this.f19368x);
                UploadImagePagerAdapter wVar = this.f19367w;
                if (wVar != null) {
                    bundle.putStringArrayList("upload_image_path_list", wVar.m933n());
                } else {
                    MutabilityOwnership.m3737u("imageAdapter");
                    throw null;
                }
            } else {
                MutabilityOwnership.m3737u("binding");
                throw null;
            }
        } else {
            MutabilityOwnership.m3737u("binding");
            throw null;
        }
    }
}
